package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import com.mingqijia.gassafety.webserver.dto.CallTaskDTO;
import com.mingqijia.gassafety.webserver.request.DisposeRecordRequest;
import com.mingqijia.gassafety.webserver.request.DisposeRequest;
import com.mingqijia.gassafety.webserver.request.WarningDataListRequest;
import com.mingqijia.gassafety.webserver.response.DisposeRecordResponse;
import com.mingqijia.gassafety.webserver.response.WarningDataResponse;
import com.mingqijia.gassafety.webserver.service.WarningDataService;
import com.mingqijia.gassafety.webserver.service.WarningRecordService;
import com.mingqijia.gassafety.webserver.service.impl.XFCallServiceImpl;
import com.mingqijia.gassafety.webserver.service.strategy.RunningStrategyServiceImpl;
import com.mingqijia.gassafety.webserver.service.strategy.StrategyServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName WarningDataController.java
 * @Description 告警数据
 * @createTime 2023年02月09日
 */

@RestController
@Api(tags = "告警数据")
@RequestMapping("/business/v1/warningData")
@Slf4j
public class WarningDataController {

    @Autowired
    private WarningDataService warningDataService;

    @Autowired
    private WarningRecordService warningRecordService;
    @Autowired
    private StrategyServiceImpl warnStrategy;

    @Autowired
    private RunningStrategyServiceImpl runningStrategyService;




    /**
     * 告警数据列表
     *
     * @param request
     * @return
     */
    @PostMapping("warningDataList")
    @ApiOperation(value = "告警数据列表")
    public CommonResponse<PageUtil<WarningDataResponse>> warningDataList(@RequestBody  WarningDataListRequest request) {
        return CommonResponse.success(warningDataService.warningDataList(request));
    }


    /**
     * 历史告警数据列表
     *
     * @param request
     * @return
     */
    @PostMapping("warningHistoryList")
    @ApiOperation(value = "历史告警数据列表")
    public CommonResponse<PageUtil<WarningDataResponse>> warningHistoryList(@RequestBody  WarningDataListRequest request) {
        return CommonResponse.success(warningDataService.warningHistoryList(request));
    }

    /**
     * 处置
     *
     * @param request
     * @return
     */
    @PostMapping("dispose")
    @ApiOperation(value = "处置")
    public CommonResponse<Object> dispose(@RequestBody @Valid DisposeRequest request) {
        warningDataService.dispose(request);
        return CommonResponse.success("请求成功");
    }

    /**
     * 处理记录查询
     *
     * @param request
     * @return
     */
    @PostMapping("/disposeRecordList")
    @ApiOperation(value = "处理记录查询")
    public CommonResponse<PageUtil<DisposeRecordResponse>> disposeRecordList(@RequestBody @Valid DisposeRecordRequest request) {
        return CommonResponse.success( warningRecordService.getRecordList(request));
    }

    /**
     * 报警
     *
     * @param imei
     * @return
     */
    @GetMapping("/warnStrategy")
    @ApiOperation(value = "报警")
    public CommonResponse<PageUtil<Object>> warnStrategy(@RequestParam("imei") String imei,
                                                         @RequestParam("deviceStatus") Integer deviceStatus,
                                                         @RequestParam("concentration") Integer concentration,
                                                         @RequestParam("type") Integer type,
                                                         @RequestParam("report") Integer report
    ) {
       if (type==0)warnStrategy.warnStrategy(imei,deviceStatus,concentration);
       if (type==1)runningStrategyService.runningStrategy(imei,deviceStatus,report);
        return CommonResponse.success(null,"success");
    }

    /**
     * 处理记录查询
     *
     * @param request
     * @return
     */
    @PostMapping("/createTask")
    @ApiOperation(value = "处理记录查询")
    public CommonResponse<Object> createTask(@RequestBody  CallTaskDTO request) {
        return CommonResponse.success( warningRecordService.createTask(request));
    }

    /**
     * 处理记录查询
     *
     * @param
     * @return
     */
    @PostMapping("/createApp")
    @ApiOperation(value = "处理记录查询")
    public CommonResponse<Object> createApp(@RequestParam("appName")String appName,
                                            @RequestParam(value = "appKey",required = false)String appKey,
                                            @RequestParam(value = "appSecret",required = false)String appSecret,
                                            @RequestParam(value = "id",required = false)Integer id) {
        return CommonResponse.success( warningRecordService.createApp(appName,appKey,appSecret,id));
    }
}